package com.ruoyi.reportsnhnt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.reportsnhnt.domain.bo.ReportSnhntKytxmlBaDetailBo;
import com.ruoyi.reportsnhnt.domain.vo.ReportSnhntKytxmlBaDetailVo;
import com.ruoyi.reportsnhnt.domain.ReportSnhntKytxmlBaDetail;
import com.ruoyi.reportsnhnt.mapper.ReportSnhntKytxmlBaDetailMapper;
import com.ruoyi.reportsnhnt.service.IReportSnhntKytxmlBaDetailService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 混凝土抗压弹性模量试验检测记录详情Service业务层处理
 *
 * @author zxs
 * @date 2024-06-21
 */
@RequiredArgsConstructor
@Service
public class ReportSnhntKytxmlBaDetailServiceImpl implements IReportSnhntKytxmlBaDetailService {

    private final ReportSnhntKytxmlBaDetailMapper baseMapper;

    /**
     * 查询混凝土抗压弹性模量试验检测记录详情
     */
    @Override
    public ReportSnhntKytxmlBaDetailVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询混凝土抗压弹性模量试验检测记录详情列表
     */
    @Override
    public TableDataInfo<ReportSnhntKytxmlBaDetailVo> queryPageList(ReportSnhntKytxmlBaDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportSnhntKytxmlBaDetail> lqw = buildQueryWrapper(bo);
        Page<ReportSnhntKytxmlBaDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询混凝土抗压弹性模量试验检测记录详情列表
     */
    @Override
    public List<ReportSnhntKytxmlBaDetailVo> queryList(ReportSnhntKytxmlBaDetailBo bo) {
        LambdaQueryWrapper<ReportSnhntKytxmlBaDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportSnhntKytxmlBaDetail> buildQueryWrapper(ReportSnhntKytxmlBaDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportSnhntKytxmlBaDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportSnhntKytxmlBaDetail::getExcelId, bo.getExcelId());
        lqw.eq(StringUtils.isNotBlank(bo.getShijbh()), ReportSnhntKytxmlBaDetail::getShijbh, bo.getShijbh());
        lqw.eq(StringUtils.isNotBlank(bo.getShijcc()), ReportSnhntKytxmlBaDetail::getShijcc, bo.getShijcc());
        lqw.eq(bo.getJixhz() != null, ReportSnhntKytxmlBaDetail::getJixhz, bo.getJixhz());
        lqw.eq(bo.getChengymj()!=null, ReportSnhntKytxmlBaDetail::getChengymj, bo.getChengymj());
        lqw.eq(bo.getZhouxkyqd() != null, ReportSnhntKytxmlBaDetail::getZhouxkyqd, bo.getZhouxkyqd());
        lqw.eq(bo.getHuansxs() != null, ReportSnhntKytxmlBaDetail::getHuansxs, bo.getHuansxs());
        lqw.eq(bo.getZhouxkyqdpj() != null, ReportSnhntKytxmlBaDetail::getZhouxkyqdpj, bo.getZhouxkyqdpj());
        lqw.eq(bo.getZhonghz() != null, ReportSnhntKytxmlBaDetail::getZhonghz, bo.getZhonghz());
        lqw.eq(bo.getChuhz() != null, ReportSnhntKytxmlBaDetail::getChuhz, bo.getChuhz());
        lqw.eq(bo.getCelbj() != null, ReportSnhntKytxmlBaDetail::getCelbj, bo.getCelbj());
        lqw.eq(bo.getShijcymj() != null, ReportSnhntKytxmlBaDetail::getShijcymj, bo.getShijcymj());
        lqw.eq(bo.getDuizsz() != null, ReportSnhntKytxmlBaDetail::getDuizsz, bo.getDuizsz());
        lqw.eq(bo.getDuizsy() != null, ReportSnhntKytxmlBaDetail::getDuizsy, bo.getDuizsy());
        lqw.eq(bo.getCessz() != null, ReportSnhntKytxmlBaDetail::getCessz, bo.getCessz());
        lqw.eq(bo.getCessy() != null, ReportSnhntKytxmlBaDetail::getCessy, bo.getCessy());
        lqw.eq(StringUtils.isNotBlank(bo.getKangytxml()), ReportSnhntKytxmlBaDetail::getKangytxml, bo.getKangytxml());
        lqw.eq(bo.getDertn() != null, ReportSnhntKytxmlBaDetail::getDertn, bo.getDertn());
        lqw.eq(bo.getKangytxmlpjz() != null, ReportSnhntKytxmlBaDetail::getKangytxmlpjz, bo.getKangytxmlpjz());
        lqw.eq(StringUtils.isNotBlank(bo.getShijcch()), ReportSnhntKytxmlBaDetail::getShijcch, bo.getShijcch());
        lqw.eq(bo.getJixhzh() != null, ReportSnhntKytxmlBaDetail::getJixhzh, bo.getJixhzh());
        lqw.eq(bo.getChengymjh()!=null, ReportSnhntKytxmlBaDetail::getChengymjh, bo.getChengymjh());
        lqw.eq(bo.getZhouxkyqdh() != null, ReportSnhntKytxmlBaDetail::getZhouxkyqdh, bo.getZhouxkyqdh());
        lqw.eq(bo.getHuansxsh() != null, ReportSnhntKytxmlBaDetail::getHuansxsh, bo.getHuansxsh());
        lqw.eq(bo.getZhouxkyqdpjh() != null, ReportSnhntKytxmlBaDetail::getZhouxkyqdpjh, bo.getZhouxkyqdpjh());
        return lqw;
    }

    /**
     * 新增混凝土抗压弹性模量试验检测记录详情
     */
    @Override
    public Boolean insertByBo(ReportSnhntKytxmlBaDetailBo bo) {
        ReportSnhntKytxmlBaDetail add = BeanUtil.toBean(bo, ReportSnhntKytxmlBaDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改混凝土抗压弹性模量试验检测记录详情
     */
    @Override
    public Boolean updateByBo(ReportSnhntKytxmlBaDetailBo bo) {
        ReportSnhntKytxmlBaDetail update = BeanUtil.toBean(bo, ReportSnhntKytxmlBaDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportSnhntKytxmlBaDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除混凝土抗压弹性模量试验检测记录详情
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
